<script setup lang="ts">
import { EnumOpType} from "@renderer/assets/types";
import { useTabManagerStore } from "@renderer/store/pinia/tabManager";
import { onDeactivated, ref, onBeforeMount, computed } from "vue";
import { idHelper } from "@renderer/store/pinia/helper";
import { getActiveTabViewOp } from "@renderer/view/hooks/common";

defineProps({
  icon: {
    type: String,
    default: "",
  },
  tips: {
    type: String,
    default: "",
  },
  opType: {
    type: Object,
    default: {
      type: EnumOpType.none,
      subType: ""
    },
  },
});

const tabStore = useTabManagerStore()
const handleClick = () => {
  const newViewId = idHelper.generateNewTabId({
    tabType: 'tag'
  });
  tabStore.appendNewTabRecord(newViewId);
};
const showTip = ref(false);
onBeforeMount(() => {
  showTip.value = false;
})
onDeactivated(() => {
  showTip.value = false;
})

const {
  activeOpObjRef
} = getActiveTabViewOp()

const disabled = computed(() =>{
  if (!activeOpObjRef.value){
    return true
  }
  return false
})
</script>

<template>
  <v-tooltip
      :text="tips"
      location="bottom"
      v-model="showTip"
  >
      <template v-slot:activator="{props}">
          <div class="w-[35px]">
            <v-btn
              :disabled="disabled"
              @click="handleClick"
              block
              :ripple="false"
              v-bind="props"
            >
              <v-icon :icon="icon"></v-icon>
            </v-btn>
          </div>
      </template>
  </v-tooltip>

</template>

<style scoped>

</style>
